package com.walle.concurrenttest.pattern.future;

import java.util.concurrent.FutureTask;

/**
 * @author zhangjiapeng
 * @Package com.walle.concurrenttest.pattern.future
 * @Description: ${todo}
 * @date 2019/2/25 14:57
 */
public class FutureData extends Host {

    private  RealData realData = null;

    private boolean ready = false;

    public synchronized void setData(RealData realData){
        if(ready){
            return;
        }
        this.realData = realData;
        this.ready = true;
        this.notifyAll();

    }

    public synchronized String get(){
        while (!ready){
            try {
                this.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        return this.realData.getContent();
    }
}
